package org.example.service.impl;

import com.github.pagehelper.PageHelper;
import org.example.dao.CourseDao;
import org.example.domain.Course;
import org.example.domain.PageBean;
import org.example.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Jimmy
 * @version 1.0
 */
@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseDao courseDao;

    @Override
    public PageBean<Course> findByPage(Course course, int pagenum, int pagesize) {
        int total = courseDao.findTotal(course);
        if (total <pagesize){
            pagesize = total;
        }
        PageHelper.startPage(pagenum,pagesize);
        List<Course> courses = courseDao.findByPage(course);
        return new PageBean<>(total,pagenum,courses);
    }

    @Override
    public int addCourse(Course course) {
        return courseDao.addCourse(course);
    }

}
